

Vue.component2("a_1_0_2_26_1_dialog",{
    template:`
    <div>
  
    <el-dialog title="添加数据库" :visible.sync="dialogVisible" width="50%">
    <el-form :model="form">
      <el-form-item label="数据库 表的英文名称*">
        <el-input v-model="form.en_name"></el-input>
      </el-form-item>
      <el-form-item label="数据库 表的中文名称">
        <el-input v-model="form.ch_name"></el-input>
      </el-form-item>
      <el-form-item label="数据库 表解释">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <div class="el-form-item">
  <div  style="
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  ">额外参数</div>
        <div class="el-form-item__content">
          <div v-for="(value,key) in form.ps" :key="key" class="extra-param-tree">
  <div class="key-value-pair">
            <input 
          type="text"
          class="el-input__inner"v-model="value.k" placeholder="key"></input>
            <input 
          type="text"
          class="el-input__inner"v-model="value.v" placeholder="Value" style="margin-left: 20px;"></input>
  <button type="button" class="el-button delete-btn el-button--danger" @click="removeExtraParam(key)"><span>删除</span></button>
          </div>
        </div>
        </div>
  <button type="button" class="el-button el-button--primary" @click="addExtraParam"><!----><!----><span>添加参数</span></button>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="submitForm">确定</el-button>
    </div>
  </el-dialog>
    </div>
    `,
    data(){
      return {
        
        dialogVisible: false,
        form: {
          index:1,
          en_name: '',//英文名称
          ch_name: '',//中文名称
          note: '',//解释
          ps:{//自定义参数
  "1":{"k":"params1","v":"value1"}
  }
      }
    }
  },
  watch:{
  },
  methods:{
    初始化:function(){
      this.form.en_name='';
      this.form.ch_name='';
      this.form.index=1;
      this.form.note='';
      this.$set(this.form,'ps',{
        "1":{"k":"params1","v":"value1"}
    });
      
    },
    addExtraParam() {
      this.form.index++;
      this.form.ps[this.form.index+'']={'k':'params'+this.form.index,'v':'value'+this.form.index};
      
      this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
    },
    removeExtraParam(index) {
      delete this.form.ps[index];
      this.$set(this.form,'ps',JSON.parse(JSON.stringify(this.form.ps)));
    },
    submitForm() {
      console.log(this.form);
      try{
        this.callback(this.form);
      }catch{}
      // 在这里实现提交到 SQLite3 数据库的逻辑
      this.dialogVisible = false;
    },
  }
  
  
  }
  
  )
  a_1_0_2_26_1_open_dialog=function(obj){
    let callback=obj.callback;
    if(!window.a_1_0_2_26_1_dialog_dom){
  
        new_dom = document.createElement('a_1_0_2_26_1_dialog');  
        new_dom.id = 'a_1_0_2_26_1_dialog'; // 为div设置一个唯一的ID 
        document.body.appendChild(new_dom);
        //设置dom属性 ref值为ref_obj
        new_dom.setAttribute('ref', 'ref_obj');
        let t_deepcopy_data=JSON.parse(JSON.stringify({}));
        new_dom.setAttribute(':deepcopy_data',"deepcopy_data");//初始化vue模板的参数
        let vue_dct={'el':new_dom,data:{true:true,false:false,null:null,deepcopy_data:t_deepcopy_data}}
        let new_vue=new Vue(vue_dct);
        // window.test_vue=new_vue;
        window.a_1_0_2_26_1_dialog_dom=new_vue.$el;
        // next_dom2=new_vue.$el;
        window.a_1_0_2_26_1_dialog_vue=new_vue.$refs.ref_obj;
    }
    window.a_1_0_2_26_1_dialog_vue.dialogVisible=true;
    window.a_1_0_2_26_1_dialog_vue.初始化();
    window.a_1_0_2_26_1_dialog_vue.callback=callback;
  }

Vue.component2('a_1_0_2_26_1', {  
    template: `
        <div  :class="{ 'a_1_0_2_26_1_lines test': data.true, 'a_1_0_2_26_1_lines_onclick': data.onclick_flag }" @click="handle_click" v-show="show_flag">
        <span :style="'padding-left: '+data._space_+'px;'"></span>
        <span  v-if="data.icon1_show_flag":class="{'icon iconfont':data.true,'icon-right':data.close,'icon-down':data.close==false}"></span>
        
        <span  class="a_1_0_2_26_1_hid_line" style="color:#bcbcbc">{{data.name}}</span>
        <div style="display:inline-block;flex:1;">
        <div style="display:flex;
    justify-content: flex-end;
    display: flex;">
    
        <div  @click="click1($event,k)" v-for="(v,k) in data.icon_data"
        :key="k">
         <a_1_0_3_0_0 style="display: inline-block;"
         :deepcopy_data="v"></a_1_0_3_0_0>
        </div>
        </div>
        </div>
        </div>
`,
data(){
    return{
        show_flag:true,
        data:{
            onclick_flag:false,
            tree_data:{},//
            icon_data:{},
            icon1_show_flag:true,
            click:null,
            click_obj:null,
            true:true,
            false:false,
            close:true,
            name:"",
            _space_:0,
        }
    }
},
methods:{
    handle_click:async function(event){
        //点击当前 高亮显示
        try{//console.log("高亮",this.data.path);
this.data.tree_data.set_onclick_flag(this.data.path)}catch{}
        // /* console.log("我点击了一次")*/
        try{
            if(!this.data.tree_data.check_dct[this.data.path]){
                await this.data.刷新目录1();
            }
            /*console.log("?2")*/}
        catch{}

        if (this.data.click){
            try{
                this.data.click(event)
            
                // console.log("start click2")
            }
            catch{}
            return 
        }


        if (this.data.click_obj){
            try{
                lhp_run_func(this.data.click_obj.func,this.data.click_obj.args)
            
                // console.log("start click3")
            }
            catch{}
            return 
        }
        try{
            this.data.click_handle(this.data.path,this.data.close);
        }catch{}
    },
    click1:async function(event,k){
       /* console.log(',,,',this.data.icon_data[k].click)*/
        lhp_run_func(this.data.icon_data[k].click);
        if(!this.data.click_stop){event.stopPropagation();}//阻止父级

    }
},

mounted:function(){
    /*console.log("210的deepcopydata",_this.deepcopy_data)*/
let tree_data=_this.deepcopy_data.tree_data;
_this.data.全局配置对象=tree_data['全局配置对象'];
_this.data.add_new=function(data){
    
//     index:1,
//     en_name: '',//英文名称
//     ch_name: '',//中文名称
//     note: '',//解释
//     ps:{//自定义参数
// "1":{"k":"params1","v":"value1"}
// }
//更新数据 
data=JSON.parse(JSON.stringify(data));
let base_info={
    "index":0,
    "vue_name":"a_1_0_2_28_1",
    'deepcopy_data':JSON.parse(JSON.stringify(data))
}
base_info['deepcopy_data']['name']=data['en_name']+`[${data['ch_name']}]`;
//更新数据 
let update_val={
    "type":"change_data",
    "data_type":"set_list",//类型 修改数据
    update_params:[
      {//将路径为path的数据 进行 +1操作 并且存入属性add中 提供给data里面携带@add的属性调用
        name:'@index',
        path:`db_config.dict.1.base_info.index`,//数据路径
        use:'++s'
      },
    ],
    "postput":[{
        'path':`db_config.dict.1.dict.@index`,
        'data':{
            "base_info":base_info,
            "dict":{}
        }
      },
      {
        'path':`db_config.dict.1.base_info`,
        'data':{
            "index":"@index",
        }
      },
    
    ],
  }
//向服务端websocket发送消息
_this.data.全局配置对象.更新(update_val);
}


_this.data.icon_data={
    90:{
        icon_class:"icon iconfont icon-path",
        hovertext:"复制配置路径,用于流程中配置设参",
        add_show:false,
        click:async function(){

        //     if(!_this.data.db_id){
        //         let path_l=_this.data.path.split(".");
        //         _this.data.dir1_id=path_l[path_l.length-1];
        //     }
        //   let copy_data=`a_${cookie_read("easyedit_userid")}_${_this.data.dir1_id}`
            copy_text('db_config.dict.1'); 
            Vue.prototype.$notify({type: 'success',message: '已拷贝配置路径:db_config.dict.1'})
        }
        },
    100:{
        icon_class:"icon iconfont icon-shujuku",
        hovertext:"添加新数据库",
        click:async function(){
            a_1_0_2_26_1_open_dialog({callback:_this.data.add_new});
        // _this.$prompt('输入新数据库', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //   }).then(({ value }) => {
        //     try{_this.data.add_new(value);}
        //     catch (err){
        //         console.log("出错..",err)
        //     }
            
        //   }).catch(() => {
        //     _this.$message({
        //       type: 'info',
        //       message: '取消输入'
        //     });       
        //   });
        }
        },
}


}

})